#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<pthread.h>
#include<sys/types.h>
#include<unistd.h>
int g_var = 9;
//线程执行函数
void *mythread(void *arg)
{
	printf("child thread,pid==[%d],id==[%ld]\n",getpid(),pthread_self());
	int a = 9;
	printf("[%p]\n",&g_var);
	pthread_exit(&g_var);
}


//创建子线程
int main()
{
	pthread_t thread;
	int ret = pthread_create(&thread,NULL,mythread,NULL);
	if(ret !=0)
	{
		printf("pthread_creat error,[%s]\n",strerror(ret));
		return -1;
	}
	printf("main thread,pid==[%d],id==[%ld]\n",getpid(),pthread_self());
	
	//回收子进程
	void *p;
	pthread_join(thread,&p);
	int n  = *(int*)p;
	printf("child exit status:[%d],[%p]\n",n, p);
	return 0;
}
